package hiultra.com.scollrecycle;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

/**
 * @author : 繁华 .
 * @data : 2018/1/17,10:47;
 * @motto : 人生的烦恼，多在于知道的太多，而做的太少。
 * @explain :
 */
public class Adapter extends RecyclerView.Adapter<Adapter.MessageViewHodlde> {

    private Context mContext;
    private List<String> mMessageBeanList;
    private LayoutInflater inflater;
    LinearLayout hscrollerview1;

    public Adapter(Context context, List<String> messageBeanList) {
        this.mContext = context;
        this.mMessageBeanList = messageBeanList;
        inflater=LayoutInflater.from(mContext);
    }

    @Override
    public MessageViewHodlde onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=inflater.inflate(R.layout.item,parent,false);
        MessageViewHodlde messageViewHodlde=new MessageViewHodlde(view);
        return messageViewHodlde;
    }

    @Override
    public void onBindViewHolder(MessageViewHodlde holder, int position) {
        holder.mTimeMessage.setText(mMessageBeanList.get(position));
        setData2(hscrollerview1,MainActivity.initData());
    }

    @Override
    public int getItemCount() {
        return mMessageBeanList.size();
    }

    public class MessageViewHodlde extends RecyclerView.ViewHolder {

        private final TextView mTimeMessage;
        public MessageViewHodlde(View itemView) {
            super(itemView);
            mTimeMessage = (TextView)itemView.findViewById(R.id.time_message);
            hscrollerview1=itemView.findViewById(R.id.hscrollerview11);

        }
    }
    private void setData2(LinearLayout hscrollerview, List<String> list) {
        // ③ 再循环添加后面的数据
        for (int i = 0; i < list.size(); i++) {
            View view = View.inflate(mContext, R.layout.item_hscollerview0, null);
            TextView tv1 = (TextView) view.findViewById(R.id.tv0);
            //创建好TextView后就立马给它设置点击事件的监听
            tv1.setText(list.get(i));
            //添加进去
            hscrollerview.addView(view);
        }
    }
}